package cn.signalpha.modules.queue.handle;

import cn.signalpha.core.tool.utils.ObjectUtil;
import cn.signalpha.modules.shop.entity.Order;
import cn.signalpha.modules.shop.service.OrderService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 订单自动取消
 *
 * @author signalpha
 */
@AllArgsConstructor
@Component("orderCancel")
public class OrderCancel implements RedisDelayQueueHandle<String> {

	private final OrderService orderService;

	@Override
	public void execute(String orderId) {
		Order order = orderService.getById(orderId);
		if(ObjectUtil.isNotEmpty(order) && order.getOrderStatus() == 0){
			orderService.cancelOrder(order.getId(), order.getUserId());
		}
	}
	
}
